/**
 * 
 */
package org.vsg.common.pagination;

/**
 * @author Bill Vison
 *
 */
public abstract class AbstractAdvancedPagination extends AbstractPagination
		implements AdvancedPagination {
	
	protected int groupingSize;
	
	protected int groupingIndex;
	
	protected int totalGrouping;

	protected final int FIRSTGROUPINGINDEX = 0;
	
	protected int LASTGROUPINGINDEX;	
	
	/**
	 * @return Returns the groupingSize.
	 */
	public int getGroupingSize() {
		return groupingSize;
	}

	/**
	 * @param groupingSize The groupingSize to set.
	 */
	public void setGroupingSize(int groupingSize) {
		this.groupingSize = groupingSize;
	}

	/**
	 * @param groupingIndex The groupingIndex to set.
	 */
	public void setGroupingIndex(int groupingIndex) {
		this.groupingIndex = groupingIndex;
	}

	/* (non-Javadoc)
	 * @see org.vsg.commons.util.pagination.AdvancedPagination#getFirstGrouping()
	 */
	public int getFirstGrouping() {
		// TODO Auto-generated method stub
		return FIRSTGROUPINGINDEX;
	}

	/* (non-Javadoc)
	 * @see org.vsg.commons.util.pagination.AdvancedPagination#getLastGrouping()
	 */
	public int getLastGrouping() {
		// TODO Auto-generated method stub
		return LASTGROUPINGINDEX;
	}

	/* (non-Javadoc)
	 * @see org.vsg.commons.util.pagination.AdvancedPagination#getGroupingIndex()
	 */
	public int getGroupingIndex() {
		// TODO Auto-generated method stub
		return groupingIndex;
	}

	/* (non-Javadoc)
	 * @see org.vsg.commons.util.pagination.AdvancedPagination#getTotalGroupings()
	 */
	public int getTotalGrouping() {
		// TODO Auto-generated method stub
		return totalGrouping;
	}

	/* (non-Javadoc)
	 * @see org.vsg.commons.util.pagination.AdvancedPagination#getGroupingOfPageIndex(int)
	 */
	public int[] getGroupingOfPageIndex(int groupingNumber) {
		// TODO Auto-generated method stub
		int startPageIndex = this.groupingSize * groupingNumber;
		
		int maxPageIndex = this.groupingSize * (groupingNumber + 1) > this.LASTPAGEINDEX ? this.totalPages  : this.groupingSize * (groupingNumber + 1);
		
		int[] pageIndexArray = new int[maxPageIndex - startPageIndex];
		
		for (int i = 0 ; i < pageIndexArray.length ;i++) {
			pageIndexArray[i] = startPageIndex + i;
		}

		return pageIndexArray;
	}

}
